@extends('admin.layouts.master')
@section('css')

    <style>
        /*搜索框所在的区域*/
        .main_header{
            float: left;
            margin-top: 8px;
            width:100%;
            height: 100px;
            line-height: 100px;

        }
        .main_header_search{
            float: left;
            width: 155px;
            position: relative;
        }
        .main_header_search input{
            border-radius:6px;
            width: 180px;
            height: 40px;
            margin-top: 30px;
            border: 0px solid;
        }
        {{--.main_header_search input:hover{--}}
            {{--box-shadow: 0 8px 12px rgba(0,0,0,0.2);--}}
        {{--}--}}
        {{--.icon_fdj{--}}
            {{--z-index: 10;--}}
            {{--top: 40px;--}}
            {{--left:5px;--}}
            {{--position: absolute;--}}
            {{--background: url("{{asset('images/search_icon.png')}}") no-repeat 0 0;--}}
            {{--width: 26px;--}}
            {{--height: 26px;--}}
        {{--}--}}
        {{--.main_header_search input{--}}
            {{--padding-left:45px;--}}
            {{--font-size: 16px;--}}
            {{--color:#ccc;--}}
        {{--}--}}
        /*================*/
        .main_header_add{
            float: right;
            width: 326px;
            height: 100px;
            line-height: 100px;
            text-align: right;

        }
        .add_box {
            float: left;
            width: 90px;
            height: 40px;
            margin-top:34px;
            background: #fff;
            line-height: 40px;
            cursor: pointer;
            border-radius: 6px;
            margin-left:17px;
        }
        .add_model{
            margin-top: -40px;
        }
        .add_box:hover{
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }

        .add_box img{
            float:left;
            margin-top:6px;
            margin-left:6px;
            width: 28px;
            height: 28px;
            line-height: 40px;
        }
        .add_box span{
            float: left;
            font-size:18px;
            margin-left: 8px;
            color:  #24a7f6;
        }
        /*================导入的样式*/
        .file_change{
            float: left;
            font-size:18px;
            margin-left: 8px;
            color:  #24a7f6;
        }

        /*======主要内容区=====*/
        .main_form{
            float: left;
            width: 100%;
            height: 783px;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 8px 12px rgba(0,0,0,0.2);
        }
        .main_formlist{
            margin-top:30px;
        }
        .main_table{
            width: 94%;
            margin: 0 auto;
            border: 1px solid #B1B1B1;
        }
        .main_table tr{
            height: 15px;
            width: 100%;
        }
        .main_table tr th{
            text-align: center;
            line-height: 20px;
            height: 20px;
            font-size: 18px;
        }
        .main_table tr td{
            text-align: center;
        }
        /*laravel自带的分页样式*/
     .boot_fenye{
         margin: 0 auto;
         margin-top:2px;
         width: 94%;
         height: 55px;
     }
     .boot_page{
     	float: right;

     }
     .boot_page_di{
     	margin-left: 10px;
     	float: left;
     	text-align: right;
     	font-size: 14px;
     	height: 74px;
     	line-height: 74px;

     }
      .boot_page_di_span{
      	width: 34px;
      	height: 34px;
        border: 1px solid #D6D6D1;
      }
     .boot_page_total{
     	margin-left: 10px;
     	float:left;
     	text-align: right;
     	font-size: 14px;
     	height: 74px;
     	line-height: 74px;


     }
        .boot_choose{
        	margin-left:20px;
            float:right;
        }
        /*======操作中的编辑与删除的样式======*/
        .formlist_handle a{
            font-size:18px;
            text-decoration: none;
        }
        .formlist_edit{
            color: #79C9F7;
        }
        .formlist_destory{
            color: red;
        }
        /*master引入后显示=====商品管理*/
        .goods_manage{
            background: #393F64;
        }
        /*bootstrap-js弹窗的css*/
        .modal_info{
            padding-left: 90px;
            margin: 0 auto;

        }
        .blinfo{
            width: 400px;
            height: 70px;

        }
        .blinfo span{

            /* padding-left: 163px;*/
            font-size: 16px;
            font-weight: 600;
        }
        .blinfo input{

            margin-top: 12px;
            width: 100%;
            height: 40px;
        }
        .blinfo_sex{
            margin-top: 12px;
            width: 100%;
            height: 40px;
        }

        .upload{
            padding: 5px 10px;
            height:13px;
            line-height: 13px;
            position: relative;
            font-size: 18px;
            text-decoration: none;

        }
        .file_change{
            position: absolute;
            overflow: hidden;
            width:83px;
            height: 43px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        /*选择照片的样式*/
        .a-upload {
            padding: 4px 10px;
            height: 40px;
            width: 400px;
            line-height: 40px;
            text-align: center;
            position: relative;
            cursor: pointer;
            color: #888;
            background: white;
            border: 1px solid #A9A9A9;
            text-decoration:none;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }

        .a-upload  input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        /*.add_dao {*/
            /*float: left;*/
            /*width: 90px;*/
            /*height: 40px;*/
            /*margin-top: 33px;*/
            /*background: #fff;*/
            /*line-height: 40px;*/
            /*cursor: pointer;*/
            /*border-radius: 6px;*/
            /*margin-left:17px;*/
        /*}*/
        /*.add_dao:hover{*/
            /*box-shadow: 0 8px 12px rgba(0,0,0,0.2);*/
        /*}*/

        /*.add_dao img{*/
            /*float:left;*/
            /*margin-top:6px;*/
            /*margin-left:6px;*/
            /*width: 28px;*/
            /*height: 28px;*/
            /*line-height: 40px;*/
        /*}*/
        /*.add_dao a span{*/
            /*float: left;*/
            /*font-size:18px;*/
            /*margin-left: 8px;*/
            /*color:orange;*/
        /*}*/

        /*下面的样式*/
        /*
        .add_hover {
            float: left;
            width: 90px;
            height: 40px;
            margin-top:33px;
            background: #fff;
            line-height: 40px;
            cursor: pointer;
            border-radius: 6px;
            margin-left:15px;
        }
        .add_hover:hover{
            box-shadow:0 4px 24px rgba(0,0,0,0.21);
        }

        .add_hover img{
            float:left;
            margin-top:6px;
            margin-left:8px;
            width: 28px;
            height: 28px;
            line-height: 40px;
        }
        .add_hover span{
            float: left;
            font-size:18px;
            margin-left: 8px;
            color:orange;
        }
        */
        /*file样式的改变*/
        /*
        .addfile{
            cursor: pointer;
            position: relative;
            display: inline-block;
            overflow: hidden;
            text-decoration: none;
            text-indent: 0;

        }
        .addfile input {
            position: absolute;
            font-size: 50px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        */
    </style>

@endsection
@section('content')
    {{--@include('admin.layouts.message')--}}
    <div class="main_header clearfix">
        <div class="main_header_search clearfix">
            <form action="{{url('admin/commodity/')}}" method="post">
                {{csrf_field()}}
                <div class="input-group input_style"  style="width:200px;" >
                    <input type="text" class="form-control" placeholder=" 输入商品名称" name="search" value="{{$search or ''}}"  style="height: 40px;"/>
                    <span class="input-group-btn">
                <button type="submit" class="btn btn-info btn-search glyphicon glyphicon-search" style="margin-top:28px;background: #3FB2F7;height: 40px; "></button>
               </span>
                </div>
            </form>
        </div>

        <div class="main_header_add clearfix">
            @if(Auth::guard('admin')->user()->checkPermission('goods.create'))
            <div class="add_box" data-toggle="modal" data-target="#myModal">
                <img src="{{asset('images/add_icon.png')}}" alt="">
                <span>新增</span>
            </div>
            @endif
            @if(Auth::guard('admin')->user()->checkPermission('goods.create'))
            {{--<a href="javascript:void(0);" class="addfile">--}}
                  <div class="add_box" onmouseover="this.style.cursor='hand'">
                      <form action="" method="post" enctype="multipart/form-data" id="formlist">
                          {{csrf_field()}}
                          <input type="file" name="excel"  style="position: absolute;width: 90px;height: 40px;opacity: 0;
                          -ms-filter: 'alpha(opacity=0)';cursor:pointer;" value="" id="fileinput" onchange="fileupload()" multiple="multiple">
                         <img src="{{asset('images/lodingin_icon.png')}}" alt="">
                         <span onmouseover="this.style.cursor='hand'" style="color: orange;">导入</span>
                    </form>
                </div>
            {{--</a>--}}
            @endif
            <form action="" method="post" enctype="multipart/form-data">
                {{csrf_field()}}
                @if(Auth::guard('admin')->user()->checkPermission('goods.create'))
                      <div class="add_box">
                        <span  onclick="downloadExcel()">模板下载</span>
                    </div>
                @endif
            </form>
        </div>
    </div>
    {{--样式框的位置--}}
    <div class="main_form clearfix">
        <!-- 表格 -->
        <div class="main_formlist">
            <table class="table table-bordered main_table">
                <tbody>
                <tr>
                    <th>商品序号</th>
                    <th>商品名称</th>
                    <th>商品编号</th>
                    <th>商品分类</th>
                    <th>数量</th>
                    <th>单价</th>
                    {{--<th>上架状态</th>--}}
                    <th>操作</th>
                </tr>
                @foreach($goods as $good)
                <tr>
                    <td>{{$good['id']}}</td>
                    <td>{{$good['name']}}</td>
                    <td>{{$good['product_code']}}</td>
                    <td>{{$good['class_name']}}</td>
                    {{--数量是根据rfid来的--}}
                    <td>{{$good['nums']}}</td>
                    <td>{{$good['price']}}元</td>
                    {{--<td> 暂时不要的位置,上下架--}}
                        {{--<span is_show="{{$good->status}}" goods_id=" {{$good['id']}}" onclick="change(this)" >--}}
                        {{--@if($good->status==0)--}}
                            {{--<img src="{{asset('images/show_icon.png')}}" alt="" style="cursor: pointer;" id="odj">--}}
                           {{--@else--}}
                            {{--<img src="{{asset('images/not_showicon.png')}}" alt="" style="cursor: pointer;" id="odj">--}}
                        {{--@endif--}}
                        {{--</span>--}}
                    {{--</td>--}}
                    <td>
                        <span class="formlist_handle">
                            @if(Auth::guard('admin')->user()->checkPermission('goods.list'))
                             <a href="{{url('/admin/commodity/show',['goods_id'=>$good['id']])}}" class="formlist_edit">
                               查看</a>
                            @endif

                                @if(Auth::guard('admin')->user()->checkPermission('goods.destroy'))
                            <a href="{{url('/admin/commodity/destroy',['goods_id'=>$good['id']])}}" class="formlist_destory"
                               onclick="if(confirm('确定删除吗?')==false) return false; layer.msg('删除成功');">
                                删除</a>
                                @endif
                        </span>
                    </td>
                </tr>
                @endforeach
                </tbody>
            </table>
        </div>

       <div class="boot_fenye clearfix">
           <div class="boot_page">
                <div class="boot_page_di">第<span class="">{{ $page = isset($_GET['page'])?$_GET['page']:1}}</span>页
                </div>
                <div  class="boot_page_total">共<span>{{$total_page}}</span>页
                </div>
               <div class="boot_choose">

                       {{ $goods->appends(['search'=>$search])->links() }}

              </div>
           </div>
       </div>
    </div>
@endsection

{{--按钮新的样式--}}
<!-- Modal -->
<div style="display: none;margin-top: 100px;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header" style="background: #3D446B;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: white;"><span aria-hidden="true"><img
                                src="{{asset('/images/cancel_icon.png')}}" alt=""></span></button>
                <h4 class="modal-title" id="myModalLabel" style="color: white;text-align: center; font-size: 24px;">新增</h4>
            </div>
            <form action="" id="addForm" enctype='multipart/form-data' name="upload_form">
                {{--<input type="hidden" value="" name="class_id" />--}}
                <div class="modal-body">
                    <div class="modal_info clearfix">

                        <p class="blinfo"><span>商品类型</span><br>
                            <select name="class_id" class="form-control" style="border-radius: 0px;height: 40px;border:1px solid #A9A9A9;">
                                <option value="0">顶级分类</option>
                                @include('admin.goods_class_option',['goodsClasses'=>$goodsClasses,'sign'=>'&nbsp;&nbsp;&nbsp;&nbsp;'])
                            </select>
                        </p>

                        <p class="blinfo"><span>商品名称</span><br>
                            <input type="text" name="goods_name" value=""></p>
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="alert  alert-danger" style="color: red;width: 400px;">{{$errors->first('goods_name')}}</div>--}}
                        {{--@endif--}}
                        <p class="blinfo"><span>商品编号</span><br>
                            <input type="text" name="goods_code" value="">
                            </p>
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="alert  alert-danger" style="color: red;width: 400px;">{{$errors->first('goods_code')}}</div>--}}
                        {{--@endif--}}
                        {{--<span  style="color: red">{{session('Fails')}}</span>--}}
                        {{--<p class="blinfo"><span>商品数量</span><br>--}}
                            {{--<input type="text" name="goods_num" value=""></p>--}}
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="alert alert-danger" style="color: red;width: 400px;">{{$errors->first('goods_num')}}</div>--}}
                        {{--@endif--}}
                        <p class="blinfo"><span>商品单价</span><br>
                            <input type="text" name="goods_price" value=""></p>
                        {{--@if(count($errors) > 0)--}}
                            {{--<div class="alert alert-danger" style="color: red;width: 400px;">{{$errors->first('goods_price')}}</div>--}}
                        {{--@endif--}}
                        <p class="blinfo"><span>上传图片</span><br>
                            <a href="javascript:void(0);" class="a-upload" style="text-decoration:none;margin-top: 10px;padding-bottom: 5px;">
                            <input type="file" name="goods_img" id="" value="">选择图片
                            </a>
                        </p>
                    </div>
                </div>
                <div class="modal-footer" style="text-align: center;">
                    <button id="save" type="button"  class="btn btn-primary" style="height:40px;border: 0px solid;width: 300px;background: #2BAAF7" >提交</button>
                        {{--保存</input>--}}
                </div>
            </form>
        </div>
    </div>
</div>
@section('js')
    {{--新增表单的异步提交--}}
    <script>
        $("#save").on("click",function () {
            $("#addForm").ajaxSubmit({
                url: '/admin/commodity/store',
                dataType: 'json',
                data: $('#addForm').serialize(),
                type: 'post',
                success: function (res) {
                    if (res.status == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = '/admin/commodity';
                        });
                    }
                }
            });
        });
    </script>
    <script>
        function change(ele){
            var img = $(ele).children();//得到子节点
            var mythis = $(ele);
            var is_show = $(ele).attr('is_show');
            var goods_id = $(ele).attr('goods_id');
            $.ajax({
                url: '/admin/commodity/status' ,
                type:'post',
                data: {'is_show': is_show,'goods_id':goods_id},
                success: function (data) {
                    if (data == 1) {
                        mythis.attr('is_show', '1');//下架
                        img.attr('src','{{asset("images/not_showicon.png")}}');//子节点增加属性

                    } else {
                        mythis.attr('is_show', '0');//上架
                        img.attr('src','{{asset("images/show_icon.png")}}');
                    }
                }
            });
        }
        //商品列表的商品表信息导入成功
        function fileupload(){
            $('#formlist').ajaxSubmit({
                url:'/admin/commodity/import',
                dataType:'json',
                type:'post',
                data:$('#formlist').serialize(),
                success:function(res){
                    var input = document.getElementById('fileinput');
                    input.value='';
                    if (res.status == 0) {
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = '/admin/commodity';
                        });
                    }

                },
                error:function(xhr, type){
                    layer.msg('请检查导入的excel表格式是否正确');
                    var input = document.getElementById('fileinput');
                    input.value='';
                }
            });
        }
        //模板下载
        function downloadExcel(){
            //获取服务器地址
            var host = location.host;
            //把excel发送出来
            var url = "http://"+ host +"/admin/commodity/download";
            window.open(url);
        }

    </script>

@endsection

